// secondary_page/neighborhoodFen/neighborhoodFen.js
import {deleteUploadImg} from '../../apis/neighborhoodFen'
Page({

    /**
     * 页面的初始数据
     */
    data: {
      fileList: [
      
      ],
    },
    afterRead(event) {
      const that = this;
      const { file } = event.detail;
      // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
      wx.uploadFile({
        url: 'http://www.foreverforest.top/fileUpload/weixinUpload', // 仅为示例，非真实的接口地址
        filePath: file.url,
        name: 'file',
        formData: { "mkdirsName": 'neighborhoodFen' },
        success(res) {
          // console.log(res);
          // 上传完成需要更新 fileList
          const fileLists = that.data.fileList
          fileLists.push({ url: res.data });
          that.setData({ fileList:fileLists});
        },
      });
    },
  
    del(e){
      console.log(e);
        let list = this.data.fileList;
        for(var i=0;i<list.length;i++){
            if(list[i] == list[e.detail.index]){
              list.splice(i,1)
              this.setData({
                fileList:list
              })
            }
        }
        deleteUploadImg(e.detail.file.url,"neighborhoodFen").then((res)=>{
          console.log(res);
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})